use Component;
use Map;

package MapManager;

@ISA = qw/Component/;

sub new{
    my $class = shift;
    my $self = {};

    bless $self, $class;
    $self->init();

    return $self;
} # new

sub init{
    my $self = shift;
    
    $self->{MAPS} = {};
    $self->dependencies(qw//);
} # init

sub registerMap{
    my $self = shift;
    my ($map, $key) = (shift, shift);

    $self->{MAPS}->{$key} = $map;
}# registerMap

sub getMap{
    my $self = shift;
    my $key = shift;
    
    return $self->{MAPS}->{$key};
} # getMap

## SELECTED MAP functions
## An ALREADY REGISTERED map can be chosen as the "selected map"
## This facilitates obtaining the map later without specifying a key
## 
## The selection is done based on a KEY, not a map reference
## This means that if, at the moment of getting the selected map,
##     whatever the selected key is pointing to will be returned

# Gets the currently selected map
sub selected{
    my $self = shift;
    return $self->{MAPS}->{$self->{SELECTED}};
}

# Sets the default map
# A KEY to an ALREADY REGISTERED map must be given
# otherwise, nothing is done
sub select{
    my $self = shift;
    my $key = shift;

    if (defined ($self->{MAPS}->{$key})){
	$self->{SELECTED} = $key;
    }
}


# Unregisters a map
# Returns the now unregistered map
sub unregisterMap{
    my $self = shift;
    my $key = shift;
    
    my $map = $self->{MAPS}->{$key};
    $self->{MAPS}->{$key} = undef;

    return $map
} # unregisterMap
1;










